package com.woyowodaows.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.woyowodaows.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/25.
 */

public class MyProgressDialog {
    private Context context;
    @BindView(R.id.iv_load)
    ImageView load;
    @BindView(R.id.ll_progress)
    LinearLayout linearLayout;
    @BindView(R.id.tv_loading)
    TextView msg;
    private Dialog dialog;

    public MyProgressDialog(Context context){
        this.context = context;

    }

    public void showDialog(String str){
        View v = LayoutInflater.from(context).inflate(R.layout.view_progress,null);
        ButterKnife.bind(this,v);

        Animation animation = AnimationUtils.loadAnimation(context,R.anim.loading_progress);
        LinearInterpolator linearInterpolator = new LinearInterpolator();
        animation.setInterpolator(linearInterpolator);
        load.startAnimation(animation);
        msg.setText(str);
        dialog = new Dialog(context,R.style.loading_dialog);
        dialog .setCancelable(true);  //返回键可取消
        dialog.setContentView(linearLayout,new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        dialog.show();


    }

    public void dismiss(){
        if (dialog != null){
            dialog.dismiss();
        }

    }

}
